//
//  SFMusicFormatToken.m
//  Sofia
//
//  Created by Anton Chebotaev on 21/11/08.
//  Copyright 2008 IFMO. All rights reserved.
//

#import "SFMusicFormatToken.h"

NSString * const SFATitleToken = @"#__title__#";		
NSString * const SFAArtistToken = @"#__artist__#";		
NSString * const SFAAlbumToken = @"#__album__#";		
NSString * const SFARatingToken = @"#__raiting__#";		
NSString * const SFAGenreToken = @"#__genre__#";		

@implementation SFMusicFormatToken

@synthesize presentation;
@synthesize content;
- (id)init
{
    [self dealloc];
    @throw [NSException exceptionWithName:@"BNRBadInitCall"
								   reason:@"Initialize SFMusicFormatToken without parameters"
								 userInfo:nil];
    return nil;
}

- (id)initWithString:(NSString *)string
{
    if (![super init])
        return nil;
	if ([string isEqualToString:SFAAlbumToken])
	{
		presentation = [[NSString alloc] initWithString:@"album"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else if ([string isEqualToString:SFAArtistToken])
	{
		presentation = [[NSString alloc] initWithString:@"artist"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else if ([string isEqualToString:SFATitleToken])
	{
		presentation = [[NSString alloc] initWithString:@"title"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else if ([string isEqualToString:SFATitleToken])
	{
		presentation = [[NSString alloc] initWithString:@"title"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else if ([string isEqualToString:SFAGenreToken])
	{
		presentation = [[NSString alloc] initWithString:@"genre"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else if ([string isEqualToString:SFARatingToken])
	{
		presentation = [[NSString alloc] initWithString:@"rating"];
		style = NSDefaultTokenStyle; //NSPlainTextTokenStyle
	}
	else
	{
		presentation = [[NSString alloc] initWithString:string];
		style = NSPlainTextTokenStyle; //NSDefaultTokenStyle
	}
	content = [[NSString alloc] initWithString:string];
    return self;	
}

+ (id)tokenWithString:(NSString *)string
{
	SFMusicFormatToken *token = [[[SFMusicFormatToken alloc] initWithString:string] autorelease];
	return token;
}

- (void)dealloc
{
    [presentation release];
    [content release];
    [super dealloc];
}

- (NSString *)description
{
	return [NSString stringWithFormat:@"content '%@' presented as '%@', styled in '%d'", content, presentation, style];
}
- (NSTokenStyle)getStyle
{
	return style;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
	//NSLog(@"Enconding - %@", self);
    [coder encodeObject:presentation forKey:@"presentation"];
    [coder encodeObject:content forKey:@"content"];
    [coder encodeInt:style forKey:@"style"];
}

- (id)initWithCoder:(NSCoder *)coder
{
	[super init];
	presentation = [[coder decodeObjectForKey:@"presentation"] retain];
	content = [[coder decodeObjectForKey:@"content"] retain];
	style = [coder decodeIntForKey:@"style"];
	
	//NSLog(@"Decoded - %@", self);
	return self;
}


@end
